#!/usr/bin/python
import sys, re;

function_dict = {}
pig_code = ''
line = sys.stdin.next()

while True:
    try:
        if line.startswith('def'):

            #read in the function name
            function_name = re.match('^def (.*)\(.*\):.*$', line).groups()[0]
            python_code = line

            #read all the indented stuff and put it under this function defn
            while True:
                line = sys.stdin.next()
                if line[0] == ' ' or line[0] == '\t':
                    python_code = python_code + line
                    function_dict[function_name] = python_code
                else:
                    #we've reached the end of this function's defn, restart loop
                    break;
        else:
            #normal pig code
            pig_code = pig_code + line;

        line = sys.stdin.next()

    except StopIteration:
        break

#replace all mentions of baconsnake.FUNCTIONNAME(param)
#with baconsnake.EvalFunc('FUNCTIONNAME','FUNCTIONCODE',param)
def repl(match):
    vars = match.groups()
    return "baconsnake.EvalFunction('%s', '%s', %s)" % (vars[0], function_dict[vars[0]].replace('\n','\\n').replace('\t','\\t'), vars[1]);
pig_code = re.compile('baconsnake\.([\w]+)\(([\w$.]+)\)').sub(repl,pig_code);


#append the jars that make this stuff work
pig_code = 'register dist/baconsnake.jar;\nregister lib/jython.jar;\n\n' + pig_code;


print pig_code